using System;
using ICaveret;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;

namespace Shraga.BLL
{
	/// <summary>
	/// Summary description for CaveretSingleton.
	/// </summary>
	public class CaveretSingleton
	{
		private static CaveretSingleton m_singleton= null;
		private ICaveretClassFactory m_myCaveret = null;
		private CaveretSingleton()
		{						
			//			TcpChannel ch = new TcpChannel();
			//ChannelServices.UnregisterChannel(ch);
			//			ChannelServices.RegisterChannel(ch);

#if DEBUG
			m_myCaveret =  (ICaveret.ICaveretClassFactory)
				Activator.GetObject(typeof(ICaveret.ICaveretClassFactory),
				"tcp://istDev:1235/caveretAPI");
#elif RELEASE
			m_myCaveret =  (ICaveret.ICaveretClassFactory)
				Activator.GetObject(typeof(ICaveret.ICaveretClassFactory),
				"tcp://istDev:1235/caveretAPI");
#elif ITUR
			m_myCaveret =  (ICaveret.ICaveretClassFactory)
				Activator.GetObject(typeof(ICaveret.ICaveretClassFactory),
				"tcp://istShraga:1235/caveretAPI");
#endif
		}

		public ICaveretClassFactory CaveretCF
		{
			get { return m_myCaveret; }
		}

		public static CaveretSingleton Instance()
		{
			if (m_singleton == null)
				m_singleton = new CaveretSingleton();
			
			return m_singleton;
		}
	}
}
